package com.twohand.admin.Controller;

import com.twohand.admin.Annotation.Permission;
import com.twohand.admin.Dto.OrderCountDto;
import com.twohand.admin.Dto.SalesListQueryDto;
import com.twohand.admin.Entity.Salesman;
import com.twohand.admin.Service.SalesmanService;
import com.twohand.admin.Util.PageResponse;
import com.twohand.admin.Vo.OrderCountVo;
import com.twohand.admin.Vo.SelectOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sales")
public class SalesmanController {
    @Autowired
    SalesmanService salesmanService;
    @Permission(value = "sales:list")
    @GetMapping
    PageResponse<Salesman> getAllSales(SalesListQueryDto salesListQueryDto){
        return salesmanService.salesList(salesListQueryDto);
    }
    @Permission(value = "sales:add")
    @PostMapping
    Boolean addSales(@RequestBody Salesman salesman){
        return salesmanService.addSales(salesman);
    }
    @Permission(value = "sales:edit")
    @PutMapping
    Boolean changeSales(@RequestBody Salesman salesman){
        return salesmanService.changeSales(salesman);
    }
    @Permission(value = "sales:delete")
    @DeleteMapping("/{id}")
    Boolean delSales(@PathVariable Integer id){
        return  salesmanService.delSales(id);
    }
    @GetMapping("/setDefault")
    Boolean setDefault(Integer id){
        return salesmanService.setDefault(id);
    }

    @GetMapping("/orderCount")
    PageResponse<OrderCountVo> getOrderOunt(OrderCountDto orderCountDto){
        return salesmanService.getOrderCountBySale(orderCountDto);
    }
    @GetMapping("/options")
    List<SelectOptions> getOptions(){
        return salesmanService.getSalesOptions();
    }
}
